import {Component, OnInit} from '@angular/core';
import {format, startOfMonth, endOfMonth, subMonths} from 'date-fns';

@Component({
  selector: 'app-ecologic-water',
  templateUrl: './ecologic-water.component.html',
  styleUrls: ['./ecologic-water.component.scss']
})
export class EcologicWaterComponent implements OnInit {
  yearValue = 2020;
  lastMonth = subMonths(new Date(), 1);
  monthPickerValue = this.lastMonth.getMonth();
  rangePickerValue = [startOfMonth(this.lastMonth), endOfMonth(this.lastMonth)];
  radioValue = 'single';

  constructor() {
  }

  ngOnInit(): void {
  }

  monthPickerChange(e): void {
    const start = startOfMonth(new Date(this.yearValue, e, 1));
    const end = endOfMonth(new Date(this.yearValue, e, 1));
    this.rangePickerValue = [start, end];
  }

  rangePickerValueChange(e): void {
    this.yearValue = null;
    this.monthPickerValue = null;
  }

  yearChange(e): void {
    const start = startOfMonth(new Date(e, this.monthPickerValue, 1));
    const end = endOfMonth(new Date(e, this.monthPickerValue, 1));
    this.rangePickerValue = [start, end];
  }
}
